﻿Imports System.Security.Cryptography
Imports System.Text
Public Class ctrSeguranca
    Inherits ctrPadrao

#Region "Variáveis"
    Private objSeguranca As New Persistencia.perSeguranca
#End Region

#Region "Criptografia"

    Public Function criptografar(ByVal sSenha As String) As String

        Try
            Return Me.objSeguranca.criptografar(sSenha)
        Catch ex As Exception
            Throw New Exception("Ocorreu um erro no método 'criptografar'. " & Environment.NewLine & Environment.NewLine & ex.Message)
        End Try

    End Function

    Public Function descriptografar(ByVal sSenha As String) As String

        Try
            Return Me.objSeguranca.descriptografar(sSenha)
        Catch ex As Exception
            Throw New Exception("Ocorreu um erro no método 'descriptografar'. " & Environment.NewLine & Environment.NewLine & ex.Message)
        End Try

    End Function

#End Region

#Region "Backup"
    Public Function GerarBackup(ByVal sDiretorio As String) As Boolean
        Dim sNomeBkp As String = sDiretorio & "\" & Date.Now.ToString("ddMMyyyy") & ".bak"

        If (IO.File.Exists(sNomeBkp)) Then
            Kill(sNomeBkp)
        End If

        Return objSeguranca.GerarBackup(sNomeBkp)

    End Function

    Public Function RestaurarBackup(ByVal sDiretorio As String, ByVal sSenha As String) As Boolean

        Return objSeguranca.RestaurarBackup(sDiretorio, sSenha)

    End Function
    Public Function DiretorioBanco() As String
        Dim sDiretorio As String

        sDiretorio = objSeguranca.DiretorioMdf
        sDiretorio = Left(sDiretorio, InStrRev(sDiretorio, "\"))

        Return sDiretorio

    End Function
    Public Function NomeBanco() As String

        Return objSeguranca.NomeBanco

    End Function
    Public Function Servidor() As String

        Return objSeguranca.Servidor

    End Function
#End Region

End Class
